<?php

/**
 * This is the model class for table "tbl_benefactor_batch".
 *
 * The followings are the available columns in table 'tbl_benefactor_batch':
 * @property integer $id
 * @property string $receipt_number
 * @property string $received_date
 * @property string $notes
 * @property integer $id_liaison
 * @property integer $id_benefactor
 *
 * The followings are the available model relations:
 * @property User $idLiaison
 * @property Benefactor $idBenefactor
 * @property Item[] $items
 */
class BenefactorBatch extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return BenefactorBatch the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_benefactor_batch';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('receipt_number,id_liaison,id_benefactor,received_date', 'required'),
			array('receipt_number', 'unique'),
			array('id_liaison, id_benefactor', 'numerical', 'integerOnly'=>true),
			array('receipt_number', 'length', 'max'=>256),
			array('received_date, notes', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, receipt_number, received_date, notes, id_liaison, id_benefactor', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idLiaison' => array(self::BELONGS_TO, 'User', 'id_liaison'),
			'idBenefactor' => array(self::BELONGS_TO, 'Benefactor', 'id_benefactor'),
			'items' => array(self::HAS_MANY, 'Item', 'id_batch'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'receipt_number' => 'Receipt Number',
			'received_date' => 'Received Date',
			'notes' => 'Notes',
			'id_liaison' => 'Liaison',
			'id_benefactor' => 'Benefactor',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('receipt_number',$this->receipt_number,true);
		$criteria->compare('received_date',$this->received_date,true);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('id_liaison',$this->id_liaison);
		$criteria->compare('id_benefactor',$this->id_benefactor);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
/*	
	protected function beforeValidate()
	{
		if ($this->isNewRecord)
		{
			$this->id_liaison = Yii::app()->user->id;
		}
		return parent::beforeValidate();
	}
*/
}